﻿using System.Configuration;
using System.ServiceProcess;
using System.ComponentModel;
using System.Configuration.Install;

namespace AuctionServer
{
    [RunInstaller(true)]
    public class ProjectInstaller : Installer
    {
        private readonly string serviceName;
        private ServiceInstaller serviceInstaller;
        private ServiceProcessInstaller serviceProcessInstaller;

        public ProjectInstaller()
        {
            serviceName = ConfigurationManager.AppSettings["serviceName"] ?? "AuctionService";

            InitializeComponent();
        }
        #region 

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            serviceProcessInstaller = new ServiceProcessInstaller();
            serviceInstaller = new ServiceInstaller();
            // 
            // serviceProcessInstaller
            // 
            serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
            serviceProcessInstaller.Password = null;
            serviceProcessInstaller.Username = null;
            // 
            // serviceInstaller
            // 
            serviceInstaller.ServiceName = serviceName;
            serviceInstaller.StartType = ServiceStartMode.Automatic;
            // 
            // ProjectInstaller
            // 
            Installers.AddRange(new Installer[] {
            serviceProcessInstaller,
            serviceInstaller});

        }

        #endregion

    }
}
